/*
 * @Title: 
 * @Descripttion: 
 * @version: 
 * @Author: wzs
 * @Date: 2020-05-01 16:13:05
 * @LastEditors: wzs
 * @LastEditTime: 2020-08-16 15:39:05
 */
var bmap = require('../../utils/bmap-wx.js');
let listData = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
Page({

  data: {
    city: '哈尔滨',
    temperature: '22℃',
    weatherDesc: '晴',
    weatherDescTpye:'sunny',
    active: 0,
    limitTop: 0,
    limitBottom: 0,
    canvasShow: false,
    limit: 10,
    itemHeight: 0,
    scroll: {
      pagination: {
        page: 1,
        totalPage: 10,
        limit: 10,
        length: 100
      },
      empty: {
        img: 'http://coolui.coolwl.cn/assets/mescroll-empty.png'
      },
      refresh: {
        type: 'default',
        style: 'black',
        background: "#000"
      },
      loadmore: {
        type: 'default',
        icon: 'http://upload-images.jianshu.io/upload_images/5726812-95bd7570a25bd4ee.gif',
        background: '#f2f2f2',
        // backgroundImage: 'http://coolui.coolwl.cn/assets/bg.jpg',
        title: {
          show: true,
          text: '加载中',
          color: "#999",
          shadow: 5
        }
      }
    },
    scrollDiy: {
      pagination: {
        page: 1,
        totalPage: 10,
        limit: 10,
        length: 100
      },
      empty: {
        img: 'http://coolui.coolwl.cn/assets/mescroll-empty.png'
      },
      refresh: {
        type: 'diy',
        diyLevel: 1,
        refreshthreshold: 70,
        background: '#000', // bug
        backgroundImage: 'http://coolui.coolwl.cn/assets/bg.jpg',
        title: {
          show: true,
          text: '下拉刷新',
          color: "#000000",
          shadow: 5
        }
      },
      loadmore: {
        type: 'diy'
      }
    },
    scrollTm: {
      pagination: {
        page: 1,
        totalPage: 10,
        limit: 10,
        length: 100
      },
      empty: {
        img: 'http://coolui.coolwl.cn/assets/mescroll-empty.png'
      },
      refresh: {
        type: 'diy',
        diyLevel: 1,
        refreshthreshold: 90,
        backgroundImage: 'http://coolui.coolwl.cn/assets/tm_mui_bike.gif',
        title: {
          show: false
        }
      },
      loadmore: {
        type: 'default',
        icon: 'http://upload-images.jianshu.io/upload_images/5726812-95bd7570a25bd4ee.gif',
        title: {
          show: true,
          text: '加载中',
          color: "#999",
          shadow: 5
        }
      }
    },
    scrollJd: {
      pagination: {
        page: 1,
        totalPage: 10,
        limit: 10,
        length: 100
      },
      empty: {
        img: 'http://coolui.coolwl.cn/assets/mescroll-empty.png'
      },
      refresh: {
        type: 'diy',
        diyLevel: 2,
        refreshthreshold: 60,
        p: 0
      },
      loadmore: {
        type: 'default',
        title: {
          show: true,
          text: '上拉加载',
          color: "#000000",
          shadow: 5
        }
      }
    },
    scrollHuojian: {
      pagination: {
        page: 1,
        totalPage: 10,
        limit: 10,
        length: 100
      },
      empty: {
        img: 'http://coolui.coolwl.cn/assets/mescroll-empty.png'
      },
      refresh: {
        type: 'diy',
        diyLevel: 2,
        refreshthreshold: 100,
        background: '#FFF', // bug
        p: 0
      },
      loadmore: {
        type: 'diy'
      }
    },
    scrollDuanwu: {
      pagination: {
        page: 1,
        totalPage: 10,
        limit: 10,
        length: 100
      },
      empty: {
        img: 'http://coolui.coolwl.cn/assets/mescroll-empty.png'
      },
      refresh: {
        type: 'diy',
        diyLevel: 1,
        refreshthreshold: 90,
        backgroundImage: 'http://coolui.coolwl.cn/assets/duanwu.gif',
        title: {
          show: false
        }
      },
      loadmore: {
        type: 'default',
        icon: 'http://upload-images.jianshu.io/upload_images/5726812-95bd7570a25bd4ee.gif',
        title: {
          show: true,
          text: '加载中',
          color: "#999",
          shadow: 5
        }
      }
    },
    scrollTq: {
      pagination: {
        page: 1,
        totalPage: 10,
        limit: 10,
        length: 100
      },
      empty: {
        img: 'http://coolui.coolwl.cn/assets/mescroll-empty.png'
      },
      refresh: {
        type: 'diy',
        diyLevel: 2,
        refreshthreshold: 100,
        p: 0
      },
      loadmore: {
        type: 'default',
        title: {
          show: true,
          text: '上拉加载',
          color: "#000000",
          shadow: 5
        }
      }
    },
    list: [],
    diyList: [],
    tmList: [],
    jdList: [],
    huojianList: [],
    canvasList: []
  },

  onLoad: function (options) {
    // 使用百度地图借口查询天气
    // var that = this;
    // // 新建百度地图对象 
    // var BMap = new bmap.BMapWX({
    //   ak: 'GpSZ73vsdkaQtNlRptfgu8eA0SokG7Oq'
    // });
    // var fail = function (data) {
    //   console.log(data)
    // };
    // var success = function (data) {
    //   var weatherData = data.currentWeather[0];
    //   var weatherDescTpye = ''
    //   switch (weatherData.weatherDesc) {
    //     case "晴":
    //       weatherDescTpye = "sunny"
    //       break;
    //     case "多云":
    //       weatherDescTpye = "cloudy"
    //       break;
    //     case "小雨":
    //       weatherDescTpye = "rainy"
    //       break;
    //     case "雪":
    //       weatherDescTpye = "snowy"
    //       break;
    //     case "雷阵雨":
    //       weatherDescTpye = "stormy"
    //       break;

    //     default:
    //       weatherDescTpye = "sunny"
    //       break;
    //   }

    //   that.setData({
    //     city: weatherData.currentCity,
    //     temperature: weatherData.date.split("：")[1].substring(0, weatherData.date.split("：")[1].length - 1),
    //     weatherDesc: weatherData.weatherDesc,
    //     weatherDescTpye: weatherDescTpye
    //   });
    // }
    // // 发起weather请求 
    // BMap.weather({
    //   fail: fail,
    //   success: success
    // });
  },
  onReady: function () {

  },
  change: function (e) {
    this.setData({
      active: e.detail.index
    })
  },
  onShow: function () {
    this.getData('refresh', 1)
    this.getDiyData('refresh', 1)
    this.getTmData('refresh', 1)
    this.getJdData('refresh', 1)
    this.getHuoJianData('refresh', 1)
    // this.getCanvasData('refresh', 1)
  },
  getData: function (type, page) {
    let that = this
    let list = that.data.list;
    if (type == 'refresh') {
      let scroll = that.data.scroll
      scroll.pagination.page = page
      setTimeout(() => {
        that.setData({
          list: listData,
          scroll: scroll
        });
      }, 300);
    } else {
      let scroll = that.data.scroll
      scroll.pagination.page = page
      setTimeout(() => {
        if (that.data.scroll.pagination.page <= that.data.scroll.pagination.totalPage) {
          that.setData({
            list: list.concat(listData),
            scroll: scroll
          });
        }
      }, 1000);
    }
  },
  refresh: function () {
    this.getData('refresh', 1)
  },
  loadMore: function () {
    this.getData('loadMore', this.data.scroll.pagination.page + 1)
  },
  getDiyData: function (type, page) {
    let that = this
    let diyList = that.data.diyList;
    if (type == 'refresh') {
      let scrollDiy = that.data.scrollDiy
      scrollDiy.pagination.page = page
      setTimeout(() => {
        that.setData({
          diyList: listData,
          scrollDiy: scrollDiy
        });
      }, 300);
    } else {
      let scrollDiy = that.data.scrollDiy
      scrollDiy.pagination.page = page
      setTimeout(() => {
        if (that.data.scrollDiy.pagination.page <= that.data.scrollDiy.pagination.totalPage) {
          that.setData({
            diyList: diyList.concat(listData),
            scrollDiy: scrollDiy
          });
        }
      }, 1000);
    }
  },
  refreshDiy: function () {
    this.getDiyData('refresh', 1)
  },
  loadMoreDiy: function () {
    this.getDiyData('loadMore', this.data.scrollDiy.pagination.page + 1)
  },
  getTmData: function (type, page) {
    let that = this
    let tmList = that.data.tmList;

    if (type == 'refresh') {
      let tmListData = []
      for (let i = 0; i < 10; i++) {
        tmListData.push(i);
      }
      let scrollTm = that.data.scrollTm
      scrollTm.pagination.page = page
      setTimeout(() => {
        that.setData({
          tmList: tmListData,
          scrollTm: scrollTm
        });
      }, 300);
    } else {
      let tmListData = []
      for (let i = 0; i < 10; i++) {
        tmListData.push(i);
      }
      setTimeout(() => {
        if (that.data.scrollTm.pagination.page < that.data.scrollTm.pagination.totalPage) {
          let scrollTm = that.data.scrollTm
          scrollTm.pagination.page = page
          that.setData({
            tmList: tmList.concat(tmListData),
            scrollTm: scrollTm
          });
        } else {
          let scrollTm = that.data.scrollTm
          scrollTm.pagination.page = page
          that.setData({
            scrollTm: scrollTm
          });
        }
      }, 1000);
    }
  },
  refreshTm: function () {
    this.getTmData('refresh', 1)
  },
  loadMoreTm: function () {
    this.getTmData('loadMore', this.data.scrollTm.pagination.page + 1)
  },
  refreshPulling: function (e) {
    let scrollJd = this.data.scrollJd
    scrollJd.refresh.p = e.detail.p
    this.setData({
      scrollJd: scrollJd
    });
  },
  getJdData: function (type, page) {
    let that = this
    let jdList = that.data.jdList;

    if (type == 'refresh') {
      let scrollJd = that.data.scrollJd
      scrollJd.pagination.page = page
      scrollJd.refresh.p = 0
      setTimeout(() => {
        that.setData({
          jdList: listData,
          scrollJd: scrollJd
        });
      }, 300);
    } else {
      setTimeout(() => {
        if (that.data.scrollJd.pagination.page < that.data.scrollJd.pagination.totalPage) {
          let scrollJd = that.data.scrollJd
          scrollJd.pagination.page = page
          that.setData({
            jdList: jdList.concat(listData),
            scrollJd: scrollJd
          });
        } else {
          let scrollJd = that.data.scrollJd
          scrollJd.pagination.page = page
          that.setData({
            scrollJd: scrollJd
          });
        }
      }, 1000);
    }
  },
  refreshJd: function () {
    this.getJdData('refresh', 1)
  },
  loadMoreJd: function () {
    this.getJdData('loadMore', this.data.scrollJd.pagination.page + 1)
  },
  onPageScroll() {},
  getHuoJianData: function (type, page) {
    let that = this
    let huojianList = that.data.huojianList;

    if (type == 'refresh') {
      let scrollHuojian = that.data.scrollHuojian
      scrollHuojian.pagination.page = page
      scrollHuojian.refresh.p = 0
      setTimeout(() => {
        that.setData({
          huojianList: listData,
          scrollHuojian: scrollHuojian
        });
      }, 300);
    } else {
      setTimeout(() => {
        if (that.data.scrollHuojian.pagination.page < that.data.scrollHuojian.pagination.totalPage) {
          let scrollHuojian = that.data.scrollHuojian
          scrollHuojian.pagination.page = page
          that.setData({
            huojianList: huojianList.concat(listData),
            scrollHuojian: scrollHuojian
          });
        } else {
          let scrollHuojian = that.data.scrollHuojian
          scrollHuojian.pagination.page = page
          that.setData({
            scrollHuojian: scroscrollHuojianlCanvas
          });
        }
      }, 1000);
    }
  },
  loadMoreHuojian: function () {
    this.getHuoJianData('loadMore', this.data.scrollHuojian.pagination.page + 1)
  },
  refreshHuojian: function () {
    this.getHuoJianData('refresh', 1)
  },
  refreshHuojianPulling: function (e) {
    let scrollHuojian = this.data.scrollHuojian
    scrollHuojian.refresh.p = e.detail.p
    this.setData({
      scrollHuojian: scrollHuojian
    });
  },
})